/**
 * Created by smp on 2017/4/24.
 */
var modelPath=ROOT_PATH+'/majorHazard/activityRecord/';

var getSelectedInformation = function (data) {
    $("#participatingContractors").combobox("clear");
    $("#majorHazardId").val(data[0].id);
    $("#majorHazardName").textbox("setValue",data[0].devicePartName);
    $("#contactContractorName").textbox("setValue",data[0].contactContractorName);
    $("#contactContractor").val(data[0].contactContractor);
    $("#level").textbox("setValue",data[0].level);
    $("#unitName").textbox("setValue",data[0].belongsUnitName);
    var ids=data[0].contactContractor.split(",");
    var names=data[0].contactContractorName.split(",");
    var datas=[];
    for(var i=0;i<ids.length;i++){
        datas.push({"text":names[i],"id":ids[i],'value':ids[i]});
    }
    $("#participatingContractors").combobox("loadData",datas);
};
$('#majorHazardName').textbox({
    required: true,
    icons: [{
        iconCls: 'icon-search',
        handler: function () {
            WindowManager.openLayer({
                type: 2,
                title: '关键装置/要害部位',
                area: ['90%', '70%'],
                content: ROOT_PATH + '/majorHazard/informationRegistration/simpleList.shtml',
                callBack:getSelectedInformation
            });
        }
    }],
    editable: false
});

$("#precautionList").datagrid({
    iconCls: 'icon-save', //图标
    rownumbers:true,
    singleSelect:true,
    fit: true, //datagrid自适应宽度
    fitColumns: true, //列自适应宽度
    striped: true, //行背景交换
    nowap: true, //列内容多时自动折至第二行
    toolbar:'#tb',
    idField: 'id', //主键
    columns: [[//显示的列
        {field:'id',width:100,checkbox:true},
        {field:'dutyUserId',title:'问题描述',width:200},
        {field:'dutyUserId2',title:'被检单位/部门',width:200},
        {field:'dutyUserId3',title:'专业分类',width:200},
        {field:'dutyUserId4',title:'整改要求',width:200},
        {field:'dutyUserName',title:'整改期限',width:200},
        {field:'measureContent',title:'整改联络人',width:300}
    ]]
});

//表单提交
$('#btn_save').on('click',function () {
    var index=layer.confirm('是否确定保存？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        $('#form1').form('submit', {
            url: modelPath+'add.shtml',

            onSubmit: function (param) {
                param.participatingContractorsName= $("#participatingContractors").combobox("getText");
                var isValid = $(this).form('validate');
                if (!isValid) {
                    layer.close(index);
                    layer.msg("请正确填写表单")
                }
                return $(this).form('validate');
            },
            success: function (result) {
                result = $.parseJSON(result);
                if (result.success){
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    layer.msg(result.message,{time:1000,icon:1},function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        $.getIframeWindow().$('#dg1').datagrid('load');
                    });
                }else {
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message,{time:1000,icon:2});
                }
            }
        });
    });

});
